<?php

class Model_User extends Model_Document
{
	protected $_collection = 'users';

	public function isMember()
	{
		return isset($this -> _data['email']);
	}

	public function getId()
	{
		return isset($this -> _data['_id']) ? $this -> _data['_id'] : 0;
	}

	public function getEmail()
	{
		return isset($this -> _data['email']) ? $this -> _data['email'] : 'empty';
	}

	public function getGender()
	{
		return isset($this -> _data['gender']) ? $this -> _data['gender'] : 'unknow';
	}

	public function getBod()
	{
		return isset($this -> _data['bod']) ? $this -> _data['bod'] : 'bod';
	}

	public function isValidPassword($string)
	{
		return $this -> password === Helper_String::createPassword($string, $this -> password_hash);
	}

	public function setPassword($string)
	{
		$hash = $this -> password_hash = Helper_String::randomString(8, 1);
		$this -> password = Helper_String::createPassword($string, $hash);
		return $this;
	}

	public function getTitle()
	{
		if (isset($this -> _data['displayname']))
		{
			return $this -> _data['displayname'];
		}
		if (isset($this -> _data['user_id']))
		{
			return 'user '. $this -> _data['user_id'];
		}
		return 'anonymous';
	}

}
